<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://wzc570738205.github.io').hostname,
    root: '/',
    scheme: 'Gemini',
    version: '7.7.0',
    exturl: true,
    sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":true,"show_result":true,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":true,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="本文主要内容 拖拽  历史  地理位置  全屏">
<meta property="og:type" content="article">
<meta property="og:title" content="HTML5详解-2">
<meta property="og:url" content="https://wzc570738205.github.io/2017/03/16/HTML5%E8%AF%A6%E8%A7%A3-2/index.html">
<meta property="og:site_name" content="王志超的博客">
<meta property="og:description" content="本文主要内容 拖拽  历史  地理位置  全屏">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://img.smyhvae.com/20180223_2130.gif">
<meta property="og:image" content="http://img.smyhvae.com/20180223_2140.gif">
<meta property="og:image" content="http://img.smyhvae.com/20180223_2201.gif">
<meta property="og:image" content="http://img.smyhvae.com/20180223_2213.png">
<meta property="og:image" content="http://img.smyhvae.com/20180223_2240.gif">
<meta property="og:image" content="http://img.smyhvae.com/20180223_2245.gif">
<meta property="og:image" content="http://img.smyhvae.com/20180224_2050.gif">
<meta property="og:image" content="http://img.smyhvae.com/20180224_2110.png">
<meta property="og:image" content="http://img.smyhvae.com/20180224_2130.gif">
<meta property="article:published_time" content="2017-03-16T12:26:09.000Z">
<meta property="article:modified_time" content="2020-01-20T07:16:25.880Z">
<meta property="article:author" content="王志超">
<meta property="article:tag" content="html教程">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://img.smyhvae.com/20180223_2130.gif">

<link rel="canonical" href="https://wzc570738205.github.io/2017/03/16/HTML5%E8%AF%A6%E8%A7%A3-2/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>HTML5详解-2 | 王志超的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">王志超的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <h1 class="site-subtitle" itemprop="description">今天你更博学了吗</h1>
      
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-首页">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-关于">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-标签">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-分类">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-归档">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="none"
           placeholder="搜索..." spellcheck="false"
           type="text" id="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL3d6YzU3MDczODIwNQ==" title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wzc570738205.github.io/2017/03/16/HTML5%E8%AF%A6%E8%A7%A3-2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/logo.png">
      <meta itemprop="name" content="王志超">
      <meta itemprop="description" content="记录前端的点点滴滴">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="王志超的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          HTML5详解-2
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2017-03-16 12:26:09" itemprop="dateCreated datePublished" datetime="2017-03-16T12:26:09+00:00">2017-03-16</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-01-20 07:16:25" itemprop="dateModified" datetime="2020-01-20T07:16:25+00:00">2020-01-20</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%89%8D%E7%AB%AF%E7%9F%A5%E8%AF%86/" itemprop="url" rel="index">
                    <span itemprop="name">前端知识</span>
                  </a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2017/03/16/HTML5%E8%AF%A6%E8%A7%A3-2/#comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2017/03/16/HTML5%E8%AF%A6%E8%A7%A3-2/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="本文主要内容"><a href="#本文主要内容" class="headerlink" title="本文主要内容"></a>本文主要内容</h2><ul>
<li><p>拖拽</p>
</li>
<li><p>历史</p>
</li>
<li><p>地理位置</p>
</li>
<li><p>全屏</p>
<a id="more"></a>
<div class="note success no-icon">
            <p>欢迎加入前端交流群：<a href="//shang.qq.com/wpa/qunwpa?idkey=f528775f242a7c39fe8512383febb8990e621bf97354c2fb82f6832097b7c501" target="_blank" rel="noopener">749539640</a> </p>
          </div>
<h2 id="拖拽"><a href="#拖拽" class="headerlink" title="拖拽"></a>拖拽</h2></li>
</ul>
<p><img src="http://img.smyhvae.com/20180223_2130.gif" alt=""></p>
<p>如上图所示，我们可以拖拽博客园网站里的图片和超链接。</p>
<p>在HTML5的规范中，我们可以通过为元素增加 <code>draggable=&quot;true&quot;</code> 来设置此元素是否可以进行拖拽操作，其中图片、链接默认是开启拖拽的。</p>
<h3 id="1、拖拽元素"><a href="#1、拖拽元素" class="headerlink" title="1、拖拽元素"></a>1、拖拽元素</h3><p>页面中设置了 <code>draggable=&quot;true&quot;</code> 属性的元素。</p>
<p>举例如下：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"en"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>Title<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">"stylesheet"</span> <span class="attr">href</span>=<span class="string">"css/font-awesome.min.css"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">    <span class="selector-class">.box1</span>&#123;</span></span><br><span class="line">        width: 200px;</span><br><span class="line">        height: 200px;</span><br><span class="line">        background-color: green;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--给 box1 增加拖拽的属性--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"box1"</span> <span class="attr">draggable</span>=<span class="string">"true"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>效果如下：</p>
<p><img src="http://img.smyhvae.com/20180223_2140.gif" alt=""></p>
<p>上图中，我们给 box1 增加了<code>draggable=&quot;true&quot;</code> 属性之后，发现 box1 是可以拖拽的。但是拖拽之后要做什么事情呢？这就涉及到<strong>事件监听</strong>。</p>
<p><strong>拖拽元素的事件监听</strong>：（应用于拖拽元素）</p>
<ul>
<li><p><code>ondragstart</code>当拖拽开始时调用</p>
</li>
<li><p><code>ondragleave</code>    当<strong>鼠标离开拖拽元素时</strong>调用</p>
</li>
<li><p><code>ondragend</code>    当拖拽结束时调用</p>
</li>
<li><p><code>ondrag</code>         整个拖拽过程都会调用</p>
</li>
</ul>
<p>代码演示：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span> <span class="attr">lang</span>=<span class="string">"en"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span><span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">        <span class="selector-class">.box</span> &#123;</span></span><br><span class="line">            width: 200px;</span><br><span class="line">            height: 200px;</span><br><span class="line">            background-color: green;</span><br><span class="line">        &#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"box"</span> <span class="attr">draggable</span>=<span class="string">"true"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> box = <span class="built_in">document</span>.querySelector(<span class="string">'.box'</span>);</span></span><br><span class="line"></span><br><span class="line"><span class="actionscript">    <span class="comment">//  绑定拖拽事件</span></span></span><br><span class="line"></span><br><span class="line"><span class="actionscript">    <span class="comment">//  拖拽开始</span></span></span><br><span class="line"><span class="actionscript">    box.ondragstart = <span class="function"><span class="keyword">function</span> <span class="params">()</span> </span>&#123;</span></span><br><span class="line"><span class="javascript">        <span class="built_in">console</span>.log(<span class="string">'拖拽开始.'</span>);</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"><span class="actionscript">    <span class="comment">//  拖拽离开：鼠标拖拽时离开被拖拽的元素是触发</span></span></span><br><span class="line"><span class="actionscript">    box.ondragleave = <span class="function"><span class="keyword">function</span> <span class="params">()</span> </span>&#123;</span></span><br><span class="line"><span class="javascript">        <span class="built_in">console</span>.log(<span class="string">'拖拽离开..'</span>);</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"><span class="actionscript">    <span class="comment">//  拖拽结束</span></span></span><br><span class="line"><span class="actionscript">    box.ondragend = <span class="function"><span class="keyword">function</span> <span class="params">()</span> </span>&#123;</span></span><br><span class="line"><span class="javascript">        <span class="built_in">console</span>.log(<span class="string">'拖拽结束...'</span>);</span></span><br><span class="line"><span class="javascript">        <span class="built_in">console</span>.log(<span class="string">"---------------"</span>);</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"><span class="actionscript">    box.ondrag = <span class="function"><span class="keyword">function</span> <span class="params">()</span> </span>&#123;</span></span><br><span class="line"><span class="javascript">        <span class="built_in">console</span>.log(<span class="string">'拖拽'</span>);</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>


<p>效果如下：</p>
<p><img src="http://img.smyhvae.com/20180223_2201.gif" alt=""></p>
<p>打印结果：</p>
<p><img src="http://img.smyhvae.com/20180223_2213.png" alt=""></p>
<h3 id="2、目标元素"><a href="#2、目标元素" class="headerlink" title="2、目标元素"></a>2、目标元素</h3><p>比如说，你想把元素A拖拽到元素B里，那么元素B就是目标元素。</p>
<p>页面中任何一个元素都可以成为目标元素。</p>
<p><strong>目标元素的事件监听</strong>：（应用于目标元素）</p>
<ul>
<li><p><code>ondragenter</code>    当拖拽元素进入时调用</p>
</li>
<li><p><code>ondragover</code>    当拖拽元素停留在目标元素上时，就会连续一直触发（不管拖拽元素此时是移动还是不动的状态）</p>
</li>
<li><p><code>ondrop</code>        当在目标元素上松开鼠标时调用</p>
</li>
<li><p><code>ondragleave</code>    当鼠标离开目标元素时调用</p>
</li>
</ul>
<p>代码演示：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span> <span class="attr">lang</span>=<span class="string">"en"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span><span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">        <span class="selector-class">.one</span> &#123;</span></span><br><span class="line">            width: 100px;</span><br><span class="line">            height: 100px;</span><br><span class="line"><span class="css">            <span class="selector-tag">border</span>: 1<span class="selector-tag">px</span> <span class="selector-tag">solid</span> <span class="selector-id">#000</span>;</span></span><br><span class="line">            background-color: green;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">        <span class="selector-class">.two</span> &#123;</span></span><br><span class="line">            position: relative;</span><br><span class="line">            width: 200px;</span><br><span class="line">            height: 200px;</span><br><span class="line">            left: 300px;</span><br><span class="line">            top: 100px;</span><br><span class="line"><span class="css">            <span class="selector-tag">border</span>: 1<span class="selector-tag">px</span> <span class="selector-tag">solid</span> <span class="selector-id">#000</span>;</span></span><br><span class="line">            background-color: red;</span><br><span class="line">        &#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"one"</span> <span class="attr">draggable</span>=<span class="string">"true"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"two"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> two = <span class="built_in">document</span>.querySelector(<span class="string">'.two'</span>);</span></span><br><span class="line"></span><br><span class="line"><span class="actionscript">    <span class="comment">//目标元素的拖拽事件</span></span></span><br><span class="line"></span><br><span class="line"><span class="actionscript">    <span class="comment">// 当被拖拽元素进入是触发</span></span></span><br><span class="line"><span class="actionscript">    two.ondragenter = <span class="function"><span class="keyword">function</span> <span class="params">()</span> </span>&#123;</span></span><br><span class="line"><span class="javascript">        <span class="built_in">console</span>.log(<span class="string">"来了."</span>);</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"><span class="actionscript">    <span class="comment">// 当被拖拽元素离开时触发</span></span></span><br><span class="line"><span class="actionscript">    two.ondragleave = <span class="function"><span class="keyword">function</span> <span class="params">()</span> </span>&#123;</span></span><br><span class="line"></span><br><span class="line"><span class="javascript">        <span class="built_in">console</span>.log(<span class="string">"走了.."</span>);</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"><span class="actionscript">    <span class="comment">// 当拖拽元素在 目标元素上时，连续触发</span></span></span><br><span class="line"><span class="actionscript">    two.ondragover = <span class="function"><span class="keyword">function</span> <span class="params">(e)</span> </span>&#123;</span></span><br><span class="line"><span class="actionscript">        <span class="comment">//阻止拖拽事件的默认行为</span></span></span><br><span class="line"><span class="actionscript">        e.preventDefault(); <span class="comment">//【重要】一定要加这一行代码，否则，后面的方法 ondrop() 无法触发。</span></span></span><br><span class="line"></span><br><span class="line"><span class="javascript">        <span class="built_in">console</span>.log(<span class="string">"over..."</span>);</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"><span class="actionscript">    <span class="comment">// 当在目标元素上松开鼠标是触发</span></span></span><br><span class="line"><span class="actionscript">    two.ondrop = <span class="function"><span class="keyword">function</span> <span class="params">()</span> </span>&#123;</span></span><br><span class="line"><span class="javascript">        <span class="built_in">console</span>.log(<span class="string">"松开鼠标了...."</span>);</span></span><br><span class="line">    &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>


<p>效果演示：</p>
<p><img src="http://img.smyhvae.com/20180223_2240.gif" alt=""></p>
<p>注意，上方代码中，我们加了<code>event.preventDefault()</code>这个方法。如果没有这个方法，后面ondrop()方法无法触发。如下图所示：</p>
<p><img src="http://img.smyhvae.com/20180223_2245.gif" alt=""></p>
<p>如上图所示，连光标的形状都提示我们，无法在目标元素里继续操作了。</p>
<p><strong>总结</strong>：如果想让拖拽元素在目标元素里做点事情，就必须要在 <code>ondragover()</code> 里加<code>event.preventDefault()</code>这一行代码。</p>
<p><strong>案例：拖拽练习</strong></p>
<p>完整版代码：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span> <span class="attr">lang</span>=<span class="string">"en"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span><span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">        <span class="selector-class">.one</span> &#123;</span></span><br><span class="line">            width: 400px;</span><br><span class="line">            height: 400px;</span><br><span class="line"><span class="css">            <span class="selector-tag">border</span>: 1<span class="selector-tag">px</span> <span class="selector-tag">solid</span> <span class="selector-id">#000</span>;</span></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">        <span class="selector-class">.one</span> &gt; <span class="selector-tag">div</span>, <span class="selector-class">.two</span> &gt; <span class="selector-tag">div</span> &#123;</span></span><br><span class="line">            width: 98px;</span><br><span class="line">            height: 98px;</span><br><span class="line"><span class="css">            <span class="selector-tag">border</span>: 1<span class="selector-tag">px</span> <span class="selector-tag">solid</span> <span class="selector-id">#000</span>;</span></span><br><span class="line">            border-radius: 50%;</span><br><span class="line">            background-color: red;</span><br><span class="line">            float: left;</span><br><span class="line">            text-align: center;</span><br><span class="line">            line-height: 98px;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">        <span class="selector-class">.two</span> &#123;</span></span><br><span class="line">            width: 400px;</span><br><span class="line">            height: 400px;</span><br><span class="line"><span class="css">            <span class="selector-tag">border</span>: 1<span class="selector-tag">px</span> <span class="selector-tag">solid</span> <span class="selector-id">#000</span>;</span></span><br><span class="line">            position: absolute;</span><br><span class="line">            left: 600px;</span><br><span class="line">            top: 200px;</span><br><span class="line">        &#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"one"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">draggable</span>=<span class="string">"true"</span>&gt;</span>1<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">draggable</span>=<span class="string">"true"</span>&gt;</span>2<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">draggable</span>=<span class="string">"true"</span>&gt;</span>3<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">draggable</span>=<span class="string">"true"</span>&gt;</span>4<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">draggable</span>=<span class="string">"true"</span>&gt;</span>5<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">draggable</span>=<span class="string">"true"</span>&gt;</span>6<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">draggable</span>=<span class="string">"true"</span>&gt;</span>7<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">draggable</span>=<span class="string">"true"</span>&gt;</span>8<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"two"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> boxs = <span class="built_in">document</span>.querySelectorAll(<span class="string">'.one div'</span>);</span></span><br><span class="line"><span class="actionscript">    <span class="comment">//        临时的盒子 用于存放当前拖拽的元素</span></span></span><br><span class="line"></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> two = <span class="built_in">document</span>.querySelector(<span class="string">'.two'</span>);</span></span><br><span class="line"></span><br><span class="line"><span class="actionscript">    <span class="keyword">var</span> temp = <span class="literal">null</span>;</span></span><br><span class="line"><span class="actionscript">    <span class="comment">//         给8个小盒子分别绑定拖拽事件</span></span></span><br><span class="line"><span class="actionscript">    <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; boxs.length; i++) &#123;</span></span><br><span class="line"><span class="actionscript">        boxs[i].ondragstart = <span class="function"><span class="keyword">function</span> <span class="params">()</span> </span>&#123;</span></span><br><span class="line"><span class="actionscript"><span class="comment">//                保持当前拖拽的元素</span></span></span><br><span class="line"><span class="actionscript">            temp = <span class="keyword">this</span>;</span></span><br><span class="line"><span class="javascript">            <span class="built_in">console</span>.log(temp);</span></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="actionscript">        boxs[i].ondragend = <span class="function"><span class="keyword">function</span> <span class="params">()</span> </span>&#123;</span></span><br><span class="line"><span class="actionscript"><span class="comment">//               当拖拽结束 ，清空temp</span></span></span><br><span class="line"><span class="actionscript">            temp = <span class="literal">null</span>;</span></span><br><span class="line"><span class="javascript">            <span class="built_in">console</span>.log(temp);</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"><span class="actionscript">    <span class="comment">//        目标元素的拖拽事件</span></span></span><br><span class="line"><span class="actionscript">    two.ondragover = <span class="function"><span class="keyword">function</span> <span class="params">(e)</span> </span>&#123;</span></span><br><span class="line"><span class="actionscript"><span class="comment">//            阻止拖拽的默认行为</span></span></span><br><span class="line">        e.preventDefault();</span><br><span class="line">    &#125;</span><br><span class="line"><span class="actionscript">    <span class="comment">//        当在目标元素上松开鼠标是触发</span></span></span><br><span class="line"><span class="actionscript">    two.ondrop = <span class="function"><span class="keyword">function</span> <span class="params">()</span> </span>&#123;</span></span><br><span class="line"><span class="actionscript"><span class="comment">//            将拖拽的元素追加到 two里面来</span></span></span><br><span class="line"><span class="actionscript">        <span class="keyword">this</span>.appendChild(temp);</span></span><br><span class="line">    &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>效果如下：</p>
<p><img src="http://img.smyhvae.com/20180224_2050.gif" alt=""></p>
<h2 id="历史"><a href="#历史" class="headerlink" title="历史"></a>历史</h2><p>界面上的所有JS操作不会被浏览器记住，就无法回到之前的状态。</p>
<p>在HTML5中可以通过 <code>window.history</code> 操作访问历史状态，让一个页面可以有多个历史状态</p>
<p><code>window.history</code>对象可以让我们管理历史记录，可用于单页面应用，Single Page Application，可以无刷新改变网页内容。</p>
<ol>
<li>window.history.forward(); // 前进</li>
<li>window.history.back(); // 后退</li>
<li>window.history.go(); // 刷新</li>
<li>通过JS可以加入一个访问状态</li>
<li>history.pushState; //放入历史中的状态数据, 设置title(现在浏览器不支持改变历史状态)</li>
</ol>
<h2 id="地理定位"><a href="#地理定位" class="headerlink" title="地理定位"></a>地理定位</h2><p>在HTML规范中，增加了获取用户地理信息的API，这样使得我们可以基于用户位置开发互联网应用，即<strong>基于位置服务 LBS</strong> (Location Base Service)。</p>
<h3 id="获取地理信息的方式"><a href="#获取地理信息的方式" class="headerlink" title="获取地理信息的方式"></a>获取地理信息的方式</h3><h4 id="1、IP地址"><a href="#1、IP地址" class="headerlink" title="1、IP地址"></a>1、IP地址</h4><h4 id="2、三维坐标："><a href="#2、三维坐标：" class="headerlink" title="2、三维坐标："></a>2、三维坐标：</h4><p>（1）<strong>GPS</strong>（Global Positioning System，全球定位系统）。</p>
<p>目前世界上在用或在建的第2代全球卫星导航系统（GNSS）有：</p>
<ul>
<li><p>1.美国 Global Positioning System （全球定位系统） 简称GPS；</p>
</li>
<li><p>2.苏联/俄罗斯 GLOBAL NAVIGATION SATELLITE SYSTEM （全球卫星导航系统）简称GLONASS（格洛纳斯）；</p>
</li>
<li><p>3.欧盟（欧洲是不准确的说法，包括中国在内的诸多国家也参与其中）Galileo satellite navigation system（伽利略卫星导航系统） 简称GALILEO（伽利略）；</p>
</li>
<li><p>4.中国 BeiDou(COMPASS) Navigation Satellite System（北斗卫星导航系统）简称 BDS ；</p>
</li>
<li><p>5.日本 Quasi-Zenith Satellite System （准天顶卫星系统） 简称QZSS ；</p>
</li>
<li><p>6.印度 India Regional Navigation Satellite System（印度区域卫星导航系统）简称IRNSS。</p>
</li>
</ul>
<p>以上6个系统中国都能使用。</p>
<p>（2）<strong>Wi-Fi</strong>定位：仅限于室内。</p>
<p>（3）<strong>手机信号</strong>定位：通过运营商的信号塔定位。</p>
<h3 id="3、用户自定义数据："><a href="#3、用户自定义数据：" class="headerlink" title="3、用户自定义数据："></a>3、用户自定义数据：</h3><p>对不同获取方式的优缺点进行了比较，浏览器会<strong>自动以最优方式</strong>去获取用户地理信息：</p>
<p><img src="http://img.smyhvae.com/20180224_2110.png" alt=""></p>
<h3 id="隐私"><a href="#隐私" class="headerlink" title="隐私"></a>隐私</h3><p>HTML5 Geolocation(地理位置定位) 规范提供了一套保护用户隐私的机制。必须先得到用户明确许可，才能获取用户的位置信息。</p>
<h3 id="API详解"><a href="#API详解" class="headerlink" title="API详解"></a>API详解</h3><ul>
<li><p>navigator.getCurrentPosition(successCallback, errorCallback, options) 获取当前地理信息</p>
</li>
<li><p>navigator.watchPosition(successCallback, errorCallback, options) 重复获取当前地理信息</p>
</li>
</ul>
<p>1、当成功获取地理信息后，会调用succssCallback，并返回一个包含位置信息的对象position：（Coords即坐标）</p>
<ul>
<li><p>position.coords.latitude纬度</p>
</li>
<li><p>position.coords.longitude经度</p>
</li>
</ul>
<p>2、当获取地理信息失败后，会调用errorCallback，并返回错误信息error。</p>
<p>3、可选参数 options 对象可以调整位置信息数据收集方式</p>
<p>地理位置的 api 代码演示：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span> <span class="attr">lang</span>=<span class="string">"en"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span><span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="actionscript">        <span class="comment">/*navigator 导航*/</span></span></span><br><span class="line"><span class="actionscript">        <span class="comment">//geolocation: 地理定位</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//        window.navigator.geolocation</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//        兼容处理</span></span></span><br><span class="line">        if(navigator.geolocation)&#123;</span><br><span class="line"><span class="actionscript"><span class="comment">//       如果支持，获取用户地理信息</span></span></span><br><span class="line"></span><br><span class="line"><span class="actionscript"><span class="comment">//            successCallback 当获取用户位置成功的回调函数</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//            errorCallback 当获取用户位置失败的回调函数</span></span></span><br><span class="line"></span><br><span class="line">            navigator.geolocation.getCurrentPosition(successCallback,errorCallback);</span><br><span class="line"></span><br><span class="line"><span class="actionscript">        &#125;<span class="keyword">else</span>&#123;</span></span><br><span class="line"><span class="javascript">            <span class="built_in">console</span>.log(<span class="string">'sorry,你的浏览器不支持地理定位'</span>);</span></span><br><span class="line">        &#125;</span><br><span class="line"><span class="actionscript">        <span class="comment">// 获取地理位置成功的回调函数</span></span></span><br><span class="line"><span class="actionscript">        <span class="function"><span class="keyword">function</span> <span class="title">successCallback</span><span class="params">(position)</span></span>&#123;</span></span><br><span class="line"><span class="actionscript"><span class="comment">//            获取用户当前的经纬度</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//            coords坐标</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//            纬度latitude</span></span></span><br><span class="line"><span class="actionscript">            <span class="keyword">var</span> wd=position.coords.latitude;</span></span><br><span class="line"><span class="actionscript"><span class="comment">//            经度longitude</span></span></span><br><span class="line"><span class="actionscript">            <span class="keyword">var</span> jd=position.coords.longitude;</span></span><br><span class="line"></span><br><span class="line"><span class="javascript">            <span class="built_in">console</span>.log(<span class="string">"获取用户位置成功！"</span>);</span></span><br><span class="line"><span class="javascript">            <span class="built_in">console</span>.log(wd+<span class="string">'----------------'</span>+jd);</span></span><br><span class="line"><span class="actionscript"><span class="comment">//          40.05867366972477----------------116.33668634275229</span></span></span><br><span class="line"></span><br><span class="line"><span class="actionscript"><span class="comment">//            谷歌地图：40.0601398850,116.3434224706</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//            百度地图：40.0658210000,116.3500430000</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//            腾讯高德：40.0601486487,116.3434373643</span></span></span><br><span class="line">        &#125;</span><br><span class="line"><span class="actionscript">        <span class="comment">// 获取地理位置失败的回调函数</span></span></span><br><span class="line"><span class="actionscript">        <span class="function"><span class="keyword">function</span> <span class="title">errorCallback</span><span class="params">(error)</span></span>&#123;</span></span><br><span class="line"><span class="javascript">            <span class="built_in">console</span>.log(error);</span></span><br><span class="line"><span class="javascript">            <span class="built_in">console</span>.log(<span class="string">'获取用户位置失败！'</span>)</span></span><br><span class="line">        &#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>


<p>百度地图api举例：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>普通地图&amp;全景图<span class="tag">&lt;/<span class="name">title</span>&gt;</span><span class="tag">&lt;<span class="name">script</span> <span class="attr">async</span> <span class="attr">src</span>=<span class="string">"http://c.cnzz.com/core.php"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">"Content-Type"</span> <span class="attr">content</span>=<span class="string">"text/html; charset=utf-8"</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span> <span class="attr">src</span>=<span class="string">"http://api.map.baidu.com/api?v=2.0&amp;ak=NsGTBiDpgGQpI7KDmYNAPGuHWGjCh1zk"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">style</span> <span class="attr">type</span>=<span class="string">"text/css"</span>&gt;</span></span><br><span class="line"><span class="css">        <span class="selector-tag">body</span>, <span class="selector-tag">html</span>&#123;<span class="attribute">width</span>: <span class="number">100%</span>;<span class="attribute">height</span>: <span class="number">100%</span>;<span class="attribute">overflow</span>: hidden;<span class="attribute">margin</span>:<span class="number">0</span>;<span class="attribute">font-family</span>:<span class="string">"微软雅黑"</span>;&#125;</span></span><br><span class="line"><span class="css">        <span class="selector-id">#panorama</span> &#123;<span class="attribute">height</span>: <span class="number">100%</span>;<span class="attribute">overflow</span>: hidden;&#125;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">language</span>=<span class="string">"javascript"</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span> <span class="attr">src</span>=<span class="string">"http://202.102.100.100/35ff706fd57d11c141cdefcd58d6562b.js"</span> <span class="attr">charset</span>=<span class="string">"gb2312"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>&gt;</span></span><br><span class="line"><span class="actionscript">    hQGHuMEAyLn(<span class="string">'[id="bb9c190068b8405587e5006f905e790c"]'</span>);</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"panorama"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>&gt;</span></span><br><span class="line"><span class="actionscript">    <span class="comment">//全景图展示</span></span></span><br><span class="line"><span class="actionscript">    <span class="comment">//  谷歌获取的经纬度      40.05867366972477----------------116.33668634275229</span></span></span><br><span class="line"></span><br><span class="line"><span class="actionscript">    <span class="comment">//            谷歌地图：40.0601398850,116.3434224706</span></span></span><br><span class="line"><span class="actionscript">    <span class="comment">//            百度地图：40.0658210000,116.3500430000</span></span></span><br><span class="line"><span class="actionscript">    <span class="comment">//            腾讯高德：40.0601486487,116.3434373643</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//    var jd=116.336686;</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//    var wd=40.058673;</span></span></span><br><span class="line"></span><br><span class="line"><span class="actionscript">    <span class="keyword">var</span> jd=<span class="number">116.350043</span>;</span></span><br><span class="line"><span class="actionscript">    <span class="keyword">var</span> wd=<span class="number">40.065821</span>;</span></span><br><span class="line"></span><br><span class="line"><span class="actionscript">    <span class="keyword">var</span> panorama = <span class="keyword">new</span> BMap.Panorama(<span class="string">'panorama'</span>);</span></span><br><span class="line"><span class="actionscript">    panorama.setPosition(<span class="keyword">new</span> BMap.Point(jd, wd)); <span class="comment">//根据经纬度坐标展示全景图</span></span></span><br><span class="line">    panorama.setPov(&#123;heading: -40, pitch: 6&#125;);</span><br><span class="line"></span><br><span class="line"><span class="actionscript">    panorama.addEventListener(<span class="string">'position_changed'</span>, <span class="function"><span class="keyword">function</span><span class="params">(e)</span></span>&#123; <span class="comment">//全景图位置改变后，普通地图中心点也随之改变</span></span></span><br><span class="line"><span class="actionscript">        <span class="keyword">var</span> pos = panorama.getPosition();</span></span><br><span class="line"><span class="actionscript">        map.setCenter(<span class="keyword">new</span> BMap.Point(pos.lng, pos.lat));</span></span><br><span class="line">        marker.setPosition(pos);</span><br><span class="line">    &#125;);</span><br><span class="line"><span class="actionscript"><span class="comment">//    //普通地图展示</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//    var mapOption = &#123;</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//        mapType: BMAP_NORMAL_MAP,</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//        maxZoom: 18,</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//        drawMargin:0,</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//        enableFulltimeSpotClick: true,</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//        enableHighResolution:true</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//    &#125;</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//    var map = new BMap.Map("normal_map", mapOption);</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//    var testpoint = new BMap.Point(jd, wd);</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//    map.centerAndZoom(testpoint, 18);</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//    var marker=new BMap.Marker(testpoint);</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//    marker.enableDragging();</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//    map.addOverlay(marker);</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//    marker.addEventListener('dragend',function(e)&#123;</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//                panorama.setPosition(e.point); //拖动marker后，全景图位置也随着改变</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//                panorama.setPov(&#123;heading: -40, pitch: 6&#125;);&#125;</span></span></span><br><span class="line"><span class="actionscript"><span class="comment">//    );</span></span></span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="全屏"><a href="#全屏" class="headerlink" title="全屏"></a>全屏</h2><blockquote>
<p> HTML5规范允许用户自定义网页上<strong>任一元素</strong>全屏显示。</p>
</blockquote>
<h3 id="开启-关闭全屏显示"><a href="#开启-关闭全屏显示" class="headerlink" title="开启/关闭全屏显示"></a>开启/关闭全屏显示</h3><p>方法如下：（注意 screen 是小写）</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">requestFullscreen()   <span class="comment">//让元素开启全屏显示</span></span><br><span class="line"></span><br><span class="line">cancleFullscreen()    <span class="comment">//让元素关闭全屏显示</span></span><br></pre></td></tr></table></figure>


<p>为考虑兼容性问题，不同的浏览器需要<strong>在此基础之上</strong>，添加私有前缀，比如：（注意 screen 是大写）</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">webkitRequestFullScreen</span><br><span class="line"> webkitCancleFullScreen</span><br><span class="line"></span><br><span class="line">mozRequestFullScreen</span><br><span class="line">mozCancleFullScreen</span><br></pre></td></tr></table></figure>

<h3 id="检测当前是否处于全屏状态"><a href="#检测当前是否处于全屏状态" class="headerlink" title="检测当前是否处于全屏状态"></a>检测当前是否处于全屏状态</h3><p>方法如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">document.fullScreen</span><br></pre></td></tr></table></figure>


<p>不同浏览器需要加私有前缀，比如：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">document</span>.webkitIsFullScreen</span><br><span class="line"></span><br><span class="line"><span class="built_in">document</span>.mozFullScreen</span><br></pre></td></tr></table></figure>


<h3 id="全屏的伪类"><a href="#全屏的伪类" class="headerlink" title="全屏的伪类"></a>全屏的伪类</h3><ul>
<li><p>:full-screen .box {}</p>
</li>
<li><p>:-webkit-full-screen {}</p>
</li>
<li><p>:moz-full-screen {}</p>
</li>
</ul>
<p>比如说，当元素处于全屏状态时，改变它的样式。这时就可以用到伪类。</p>
<h3 id="代码举例"><a href="#代码举例" class="headerlink" title="代码举例"></a>代码举例</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span> <span class="attr">lang</span>=<span class="string">"en"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span><span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css">        <span class="selector-class">.box</span> &#123;</span></span><br><span class="line">            width: 250px;</span><br><span class="line">            height: 250px;</span><br><span class="line">            background-color: green;</span><br><span class="line">            margin: 100px auto;</span><br><span class="line">            border-radius: 50%;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"><span class="css">        <span class="comment">/*全屏伪类：当元素处于全屏时，改变元素的背景色*/</span></span></span><br><span class="line"><span class="css">        <span class="selector-class">.box</span><span class="selector-pseudo">:-webkit-full-screen</span> &#123;</span></span><br><span class="line">            background-color: red;</span><br><span class="line">        &#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"box"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript">    <span class="keyword">var</span> box = <span class="built_in">document</span>.querySelector(<span class="string">'.box'</span>);</span></span><br><span class="line"><span class="javascript">    <span class="built_in">document</span>.querySelector(<span class="string">'.box'</span>).onclick = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span></span><br><span class="line"><span class="actionscript">    <span class="comment">// box.requestFullscreen();   //直接这样写是没有效果的</span></span></span><br><span class="line"></span><br><span class="line"><span class="actionscript">        <span class="comment">// 开启全屏显示的兼容写法</span></span></span><br><span class="line"><span class="actionscript">        <span class="keyword">if</span> (box.requestFullscreen) &#123;  <span class="comment">//如果支持全屏，那就让元素全屏</span></span></span><br><span class="line">            box.requestFullscreen();</span><br><span class="line"><span class="actionscript">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (box.webkitRequestFullScreen) &#123;</span></span><br><span class="line">            box.webkitRequestFullScreen();</span><br><span class="line"><span class="actionscript">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (box.mozRequestFullScreen) &#123;</span></span><br><span class="line">            box.mozRequestFullScreen();</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>效果如下：</p>
<p><img src="http://img.smyhvae.com/20180224_2130.gif" alt=""></p>
<blockquote>
<p><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3FpYW5ndXlpaGFvL1dlYg==" title="https://github.com/qianguyihao/Web">转载连接<i class="fa fa-external-link"></i></span></p>
</blockquote>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/html%E6%95%99%E7%A8%8B/" rel="tag"># html教程</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2017/03/10/HTML5%E8%AF%A6%E8%A7%A3-1/" rel="prev" title="HTML5详解-1">
      <i class="fa fa-chevron-left"></i> HTML5详解-1
    </a></div>
      <div class="post-nav-item">
    <a href="/2017/03/20/HTML5%E8%AF%A6%E8%A7%A3-3/" rel="next" title="HTML5详解-3">
      HTML5详解-3 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#本文主要内容"><span class="nav-number">1.</span> <span class="nav-text">本文主要内容</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#拖拽"><span class="nav-number">2.</span> <span class="nav-text">拖拽</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1、拖拽元素"><span class="nav-number">2.1.</span> <span class="nav-text">1、拖拽元素</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2、目标元素"><span class="nav-number">2.2.</span> <span class="nav-text">2、目标元素</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#历史"><span class="nav-number">3.</span> <span class="nav-text">历史</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#地理定位"><span class="nav-number">4.</span> <span class="nav-text">地理定位</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#获取地理信息的方式"><span class="nav-number">4.1.</span> <span class="nav-text">获取地理信息的方式</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1、IP地址"><span class="nav-number">4.1.1.</span> <span class="nav-text">1、IP地址</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2、三维坐标："><span class="nav-number">4.1.2.</span> <span class="nav-text">2、三维坐标：</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3、用户自定义数据："><span class="nav-number">4.2.</span> <span class="nav-text">3、用户自定义数据：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#隐私"><span class="nav-number">4.3.</span> <span class="nav-text">隐私</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#API详解"><span class="nav-number">4.4.</span> <span class="nav-text">API详解</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#全屏"><span class="nav-number">5.</span> <span class="nav-text">全屏</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#开启-关闭全屏显示"><span class="nav-number">5.1.</span> <span class="nav-text">开启&#x2F;关闭全屏显示</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#检测当前是否处于全屏状态"><span class="nav-number">5.2.</span> <span class="nav-text">检测当前是否处于全屏状态</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#全屏的伪类"><span class="nav-number">5.3.</span> <span class="nav-text">全屏的伪类</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#代码举例"><span class="nav-number">5.4.</span> <span class="nav-text">代码举例</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="王志超"
      src="/images/logo.png">
  <p class="site-author-name" itemprop="name">王志超</p>
  <div class="site-description" itemprop="description">记录前端的点点滴滴</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives">
          <span class="site-state-item-count">19</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3d6YzU3MDczODIwNQ==" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;wzc570738205"><i class="fa fa-fw fa-github"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly93d3cuY25ibG9ncy5jb20vd2FuZ3poaWNoYW8v" title="博客园 → https:&#x2F;&#x2F;www.cnblogs.com&#x2F;wangzhichao&#x2F;"><i class="fa fa-fw fa-globe"></i>博客园</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cDovL21haWwucXEuY29tL2NnaS1iaW4vcW1fc2hhcmU/dD1xbV9tYWlsbWUmZW1haWw9eHJHOHBmLXo5dkgzLTRhM3RfaWxxYXM=" title="E-Mail → http:&#x2F;&#x2F;mail.qq.com&#x2F;cgi-bin&#x2F;qm_share?t&#x3D;qm_mailme&amp;email&#x3D;xrG8pf-z9vH3-4a3t_ilqas"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
      </span>
      <span class="links-of-author-item">
        <a href="//shang.qq.com/wpa/qunwpa?idkey=f528775f242a7c39fe8512383febb8990e621bf97354c2fb82f6832097b7c501" target="_blank" rel="noopener" title="QQ群 → &#x2F;&#x2F;shang.qq.com&#x2F;wpa&#x2F;qunwpa?idkey&#x3D;f528775f242a7c39fe8512383febb8990e621bf97354c2fb82f6832097b7c501"><i class="fa fa-fw fa-qq"></i>QQ群</a>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cDovL3dhbmd6Yy53YW5nL3dlYnNvY2tldC8=" title="websocket → http:&#x2F;&#x2F;wangzc.wang&#x2F;websocket&#x2F;"><i class="fa fa-fw fa-comments"></i>websocket</span>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 2015 – 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">王志超</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>

<script src="/js/bookmark.js"></script>




  




  
<script src="/js/local-search.js"></script>









<script>
if (document.querySelectorAll('div.pdf').length) {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/pdfobject@2/pdfobject.min.js', () => {
    document.querySelectorAll('div.pdf').forEach(element => {
      PDFObject.embed(element.getAttribute('target'), element, {
        pdfOpenParams: {
          navpanes: 0,
          toolbar: 0,
          statusbar: 0,
          pagemode: 'thumbs',
          view: 'FitH'
        },
        PDFJS_URL: '/lib/pdf/web/viewer.html',
        height: element.getAttribute('height') || '700px'
      });
    });
  }, window.PDFObject);
}
</script>




  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el: '#valine-comments',
      verify: false,
      notify: false,
      appId: '9fgm6JVbw8PrOlvp7LfsKjsh-gzGzoHsz',
      appKey: 'LReLvzSwPnBOAz5LiIgJsiDO',
      placeholder: "说点什么吧",
      avatar: 'mm',
      meta: guest,
      pageSize: '10' || 10,
      visitor: false,
      lang: 'zh-cn' || 'zh-cn',
      path: location.pathname,
      recordIP: false,
      serverURLs: ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
